﻿using NetCore8Demo.Models.PLC;

namespace NetCore8Demo.Views.PLC
{
    public partial class ShowPlcForm : Form
    {
        //public ShowPlcForm()
        //{
        //    InitializeComponent();
        //}
        List<PlcAddressInfo> _plcAddressInfoList;
        public ShowPlcForm(List<PlcAddressInfo> plcAddressInfoList)
        {
            InitializeComponent();
            _plcAddressInfoList = plcAddressInfoList;
        }

        private void showControlTimer_Tick(object sender, EventArgs e)
        {
            foreach (var item in _plcAddressInfoList)
            {
                var nameControl = this.Controls.Find("nameLabel" + item.Index, true);
                if(nameControl.Length > 0 && nameControl[0] is Label)
                {
                    nameControl[0].Text = item.Name;
                }

                var valueControl = this.Controls.Find("valueLabel" + item.Index, true);
                if (valueControl.Length > 0 && valueControl[0] is Label)
                {
                    if (item.Value.Length > 10)
                    {
                        valueControl[0].Text = item.Value.Substring(0,10);
                        toolTip1.SetToolTip(valueControl[0],  item.Value);
                    }
                    else
                    {
                        valueControl[0].Text = item.Value;
                    }
                   
                }
            }
        }

        private void ShowPLCForm_Load(object sender, EventArgs e)
        {
            //this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        }
    }
}
